<template>
  <el-dropdown>
    <span class="el-dropdown-link">
      <el-avatar> 用户 </el-avatar>
      <span style="padding: 10px">{{ name }}</span>
      <el-icon class="el-icon--right">
        <arrow-down />
      </el-icon>
    </span>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item icon="CircleClose" @click="handleExitClick"
          >退出登录</el-dropdown-item
        >
        <!-- <el-dropdown-item disabled>Action 4</el-dropdown-item> -->
        <el-dropdown-item divided>用户信息</el-dropdown-item>
        <el-dropdown-item>系统管理</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'
import { useStore } from 'vuex'
import localCache from '@/utils/caches'
import { useRouter } from 'vue-router'

export default defineComponent({
  name: 'userInfo',
  setup() {
    const router = useRouter()
    const store = useStore()
    const name = computed(() => {
      return store.state.login.userInfo.name
    })
    const handleExitClick = () => {
      localCache.deleteCache('token')
      router.push('/main')
    }
    return { name, handleExitClick }
  }
})
</script>

<style scoped lang="less">
.el-dropdown-link {
  cursor: pointer;
  color: var(--el-color-primary);
  display: flex;
  align-items: center;
}
</style>
